package com.example.lecturereservation.service;


import com.example.lecturereservation.entity.Admin;
import com.example.lecturereservation.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminService implements AdminMapper {

    @Autowired
    AdminMapper adminMapper;

    //注册功能
    public String registration(Admin admin){

        if (admin.getEmail().trim().length()==0){
            return "邮箱不能为空";
        }

        if (admin.getEmail().indexOf("@")==-1){
            return "邮箱格式不对";
        }

        //查找邮箱存在
        if (adminMapper.findByEmail(admin.getEmail())!=null){
            return "用户已经存在！";
        }

        if (admin.getPassword().trim().length()<6){
            return "密码长度必须大于6";
        }

        this.save(admin);
        return "ok";
    }


    @Override
    @Cacheable//缓存：只取1次，第二次从缓存中取数据
    public Admin getById(int id) {
        return adminMapper.getById(id);
    }

    @Override
    public void save(Admin t) {
        this.adminMapper.save(t);
    }

    @Override
    public Admin findByEmail(String email) {
        return this.adminMapper.findByEmail(email);
    }

    @Override
    public void deleteById(int id) {

    }

    @Override
    public void update(Admin t) {

    }

    @Override
    public List<Admin> getAll() {
        return null;
    }

    @Override
    public List<Admin> getPage(int start, int end) {
        return null;
    }
}
